< previous page page_600 next page >

Page 600
0600-01.jpg
Figure 15.2.
The results of using 
INSERT INTO
with COUNTER and optional fields.
Two other interesting things about the INSERT INTO statement are illustrated in the code example in Listing 15.2. Notice that the values for the JobTitles.JobPay column were surrounded by quotation marks even though the data type is CURRENCY. When you use the INSERT INTO statement, all values must be surrounded by quotation marks. SQL and Visual Basic handle any type conversions needed to insert the values into the identified fields.
The second interesting thing to note in Listing 15.2 is the order in which columns are listed in the INSERT INTO statements. If you look at each of the statements, you see that the JobTitles.JobPay column appears in different places within the field list. When you use the INSERT INTO statement, you can list the columns in any order. You only need to make sure that you list the values to be inserted in the same order in which you list the columns.
You have learned how to use the INSERT INTO statement to add individual rows to a table. This is commonly called a single-record insert. In the next section, you learn about a more powerful version of the INSERT INTO statement, commonly called an append query.
Creating Append Queries with INSERT INTO_FROM
The INSERT INTO_FROM version of the INSERT statement allows you to insert multiple records from one table into another table. This multirecord version of INSERT INTO is called an append query because it enables you to append rows from one table to the end of another table. As long as the two tables you are working with have fields with the same name, you can use the INSERT INTO_FROM statement.
The basic format of the INSERT INTO_FROM statement is
INSERT INTO TargetTable SELECT field1, field2 FROM SourceTable;
There are three important parts of the INSERT INTO_FROM statement. The first part is the TargetTable. This is the table that is updated by the statement. The second part is SELECT fields. This is a list of the fields that are updated in the TargetTable. These are also the fields that are supplied by the third part of the statementthe SourceTable. As you can see, the

 
< previous page page_600 next page >

If you like this book, buy it!